//
//  CZRefreshView.swift
//  CZRefresh
//
//  Created by tuimao on 2017/8/3.
//  Copyright © 2017年 tuimao. All rights reserved.
//

import UIKit

class CZRefreshView: UIView {
    /**
    *在UIView的动画中封装旋转动画
    * 默认是顺时针旋转
    * 就近原则
    * 要实现同方向旋转，需要调整一个非常小的数值（0.0001）
    * 如果要实现360度旋转，需要核心动画CABaseAnimation
    */
    var refreshState :CZRefreshState = .Normal{
        didSet{
            switch refreshState {
            case .Normal:
                tipLabel?.text = "继续使劲拉..."
                tipIcon?.isHidden = false
                indicator?.stopAnimating()
                
                UIView.animate(withDuration: 0.25, animations: {
                    self.tipIcon?.transform = CGAffineTransform.identity
                })
            case .Pulling:
                tipLabel?.text = "放手就刷新..."
                UIView.animate(withDuration: 0.25, animations: { 
                  self.tipIcon?.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi + 0.0001))
                })
            case .WillRefresh:
                tipLabel?.text = "正在刷新中..."
                tipIcon?.isHidden = true
                indicator?.startAnimating()
            }
        }
    }
    //父视图的高度
    var parentViewHeight:CGFloat = 0
    //指示器
    @IBOutlet weak var indicator: UIActivityIndicatorView?
   //提示标签
    @IBOutlet weak var tipLabel: UILabel?
    //提示图标
    @IBOutlet weak var tipIcon: UIImageView?
    
    class func refreshView()->CZRefreshView{
        
        let nib = UINib(nibName: "CZMeituanRefreshView", bundle: nil)
        
        return nib.instantiate(withOwner: nil, options: nil)[0] as! CZRefreshView
    }
    
}
